package com.tianyang.yukuaifuzs.module.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.View;

import androidx.core.content.ContextCompat;

import com.tianyang.yukuaifuzs.R;
import com.tianyang.yukuaifuzs.business.auth.contract.AuthConfig;
import com.tianyang.yukuaifuzs.module.dialog.interfaces.ICallbackListener;
import com.tianyang.yukuaifuzs.module.roundview.RoundTextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Description：新增店铺
 * Created by xyj on 2024/3/11
 */
public class AddStoreDialog extends Dialog {

    @BindView(R.id.tvSmallMerchant)
    RoundTextView tvSmallMerchant;
    @BindView(R.id.tvIndividualMerchant)
    RoundTextView tvIndividualMerchant;
    @BindView(R.id.tvCompanyMerchant)
    RoundTextView tvCompanyMerchant;

    private ICallbackListener<String> listener;

    private String merchantType = AuthConfig.MCH_TYPE_SMALL;

    public void setListener(ICallbackListener<String> listener) {
        this.listener = listener;
    }

    public AddStoreDialog(Context context) {
        super(context, R.style.dialog_normal);
        setContentView(R.layout.dialog_add_store);
        ButterKnife.bind(this);
    }

    private void onRefreshView() {
        switch (merchantType) {
            case AuthConfig.MCH_TYPE_SMALL:
                tvSmallMerchant.getDelegate().setStrokeColor(ContextCompat.getColor(getContext(), R.color.color_base));
                tvIndividualMerchant.getDelegate().setStrokeColor(ContextCompat.getColor(getContext(), R.color.white));
                tvCompanyMerchant.getDelegate().setStrokeColor(ContextCompat.getColor(getContext(), R.color.white));
                break;
            case AuthConfig.MCH_TYPE_INDIVIDUAL:
                tvSmallMerchant.getDelegate().setStrokeColor(ContextCompat.getColor(getContext(), R.color.white));
                tvIndividualMerchant.getDelegate().setStrokeColor(ContextCompat.getColor(getContext(), R.color.color_base));
                tvCompanyMerchant.getDelegate().setStrokeColor(ContextCompat.getColor(getContext(), R.color.white));
                break;
            case AuthConfig.MCH_TYPE_COMPANY:
                tvSmallMerchant.getDelegate().setStrokeColor(ContextCompat.getColor(getContext(), R.color.white));
                tvIndividualMerchant.getDelegate().setStrokeColor(ContextCompat.getColor(getContext(), R.color.white));
                tvCompanyMerchant.getDelegate().setStrokeColor(ContextCompat.getColor(getContext(), R.color.color_base));
                break;
        }
    }

    @OnClick({R.id.confirmRtv, R.id.tvSmallMerchant, R.id.tvIndividualMerchant, R.id.tvCompanyMerchant})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.confirmRtv:
                if(listener != null) {
                    listener.callback(merchantType);
                }
                dismiss();
                break;
            case R.id.tvSmallMerchant:
                merchantType = AuthConfig.MCH_TYPE_SMALL;
                onRefreshView();
                break;
            case R.id.tvIndividualMerchant:
                merchantType = AuthConfig.MCH_TYPE_INDIVIDUAL;
                onRefreshView();
                break;
            case R.id.tvCompanyMerchant:
                merchantType = AuthConfig.MCH_TYPE_COMPANY;
                onRefreshView();
                break;
        }
    }
}
